BUILDER R Functions

neighbours()

The neighbours() function creates a neighbours table listing neighbours for each catchment, which is an input to builder().

For an sf object of catchments with unique CATCHNUM id’s, calculates a list of neighbouring CATCHNUM pairs and returns them in a long tibble. Neighbours are defined as having at least on point in common (within 0.1m).

Usage

neighbours(
  catchments_sf
)

Arguments

  • catchments_sf: sf object of the catchments dataset with a unique identifier column: CATCHNUM.

📤 Output

A tibble of neighbouring pairs with columns CATCHNUM and neighbours.

Examples

Running the examples

  1. Download and unzip BEACONs R Tools

  2. Create the folder structure

# Set working directory
setwd("your/path/to/downloads")

dirpath <- getwd()

# Create the folder structure
treedir <- c("R","data","Builder_input")
for(d in treedir){
  if (!dir.exists(file.path(dirpath, d))) {
    dir.create(file.path(dirpath, d), recursive = TRUE)
  }
}
  1. Run the examples below.
library(dplyr)
library(sf)
library(utils)

source("./R/builder.R")

# Use all catchments as seeds with a single area target
catchments_sample <- readRDS("data/catchments_sample.rds")
neighbours(catchments_sf = catchments_sample)

# save neighbours as csv
neighbour <- neighbours(catchments_sf = catchments_sample)
write.csv(neighbour, file=file.path(dirpath,"Builder_input/neighbours.csv"), row.names=FALSE)